#include <iostream>
#include <cstdio>

#define N 510

using namespace std;

char tmp;
int map[N][N];
int n, m;

const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, -1, 1};

void dfs(int x, int y){
    if(x < 0 || y < 0 || x > m+1 || y > n+1 || map[x][y]){
        return ;
    }
    map[x][y] = 2;
    for(int i = 1; i <= 4; i++){
       int xx = x + dx[i];  int yy = y + dy[i];
       dfs(xx, yy);
    }
}

int main(){
    cin >> m >> n;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            cin >> tmp;
            if(tmp == '0')  map[i][j] = 0;
            else map[i][j] = 1; //is wall
        }
    }
    dfs(0, 0);
    int ans = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(map[i][j] == 0)  ans++;
        }
    }
    cout << ans << endl;
    return 0;
}